package com.cysyz.mylib.jpadao;

import com.cysyz.mylib.dao.engine.Query;
import com.cysyz.mylib.dao.engine.SQLQuery;

import java.util.List;

/**
 * Created by cuiyong on 2014/12/24.
 */
public class SQLQueryJPA implements SQLQuery {
    private javax.persistence.Query query;

    public SQLQueryJPA(javax.persistence.Query query) {
        this.query = query;
    }

    @Override
    public List getResultList() {
        return query.getResultList();
    }

    @Override
    public void setCacheAble(boolean isCacheAble) {
        throw new RuntimeException("cache not support");
    }

    @Override
    public Query setFirstResult(int firstResult) {
        query.setFirstResult(firstResult);
        return this;
    }

    @Override
    public Query setMaxResults(int maxResult) {
        query.setMaxResults(maxResult);
        return this;
    }

    @Override
    public void setParameter(Integer placeHolder, Object value) {
        query.setParameter(placeHolder, value);
    }

    @Override
    public void setParameter(String placeHolder, Object value) {
        query.setParameter(placeHolder, value);
    }

    @Override
    public Object getSingleResult() {
        return query.getSingleResult();
    }

    @Override
    public int execute() {
        return this.query.executeUpdate();
    }

}
